using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using Common;
using Controls;

namespace MainView.Windows
{
	public partial class RawDataWindow : Window, IComponentConnector
	{
		public RawDataWindow()
		{
			InitializeComponent();
		}

		public void SetData(List<Dot> list)
		{
			wp.Children.Clear();
			foreach (Dot item in list)
			{
				StackPanel stackPanel = new StackPanel();
				stackPanel.Orientation = Orientation.Horizontal;
				stackPanel.HorizontalAlignment = HorizontalAlignment.Left;
				stackPanel.VerticalAlignment = VerticalAlignment.Top;
				stackPanel.Margin = new Thickness(5.0, 5.0, 5.0, 5.0);
				TextBlock textBlock = new TextBlock();
				textBlock.VerticalAlignment = VerticalAlignment.Center;
				textBlock.Width = 30.0;
				textBlock.Text = item.X.ToString("0") + ":";
				textBlock.Tag = item.X;
				stackPanel.Children.Add(textBlock);
				NumericSpan numericSpan = new NumericSpan();
				numericSpan.Width = 80.0;
				numericSpan.Height = 25.0;
				numericSpan.StringFormat = "0.00";
				numericSpan.Value = item.Y;
				stackPanel.Children.Add(numericSpan);
				wp.Children.Add(stackPanel);
			}
		}

		public List<Dot> GetData()
		{
			List<Dot> list = new List<Dot>();
			foreach (StackPanel child in wp.Children)
			{
				list.Add(new Dot
				{
					X = Convert.ToInt32(((TextBlock)child.Children[0]).Tag),
					Y = ((NumericSpan)child.Children[1]).Value
				});
			}
			return list;
		}

		private void btnOK_Click(object sender, RoutedEventArgs e)
		{
			base.DialogResult = true;
			Close();
		}

		private void btnCancel_Click(object sender, RoutedEventArgs e)
		{
			Close();
		}
	}
}
